package net.sumcraft.pointconvert;

import org.black_ixx.playerpoints.PlayerPoints;
import org.bukkit.command.CommandExecutor;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.java.JavaPlugin;

/**
 * Created by 夏振 on 2017/6/30.
 */
public class PointConvert extends JavaPlugin {
    public static PlayerPoints playerPoints;
    public static FileConfiguration cfg;
    public static PointConvert pointConvert;

    public void onEnable() {
        if (hookPlayerPoints()) {
            getLogger().info("检测到PlayerPoints");

        }
        this.getCommand("zh").setExecutor((CommandExecutor) new MyCommand());

    }

    public void load() {
        saveDefaultConfig();
        reloadConfig();
        cfg = this.getConfig();
        pointConvert = this;
    }

    /**
     * Validate that we have access to PlayerPoints
     *
     * @return True if we have PlayerPoints, else false.
     */

    private boolean hookPlayerPoints() {
        final Plugin plugin = this.getServer().getPluginManager().getPlugin("PlayerPoints");
        playerPoints = PlayerPoints.class.cast(plugin);
        return playerPoints != null;
    }
}
